
library(tidyverse)
library(haven)
library(extrafont)
library(fontcm)
library(latticeExtra)
library(locfit)
library(haven)
library(fontcm)
library(data.table)
setwd("")

font_install("fontcm")
loadfonts()

dir = ""

df <- fread("build/Data_ready_with_instruments.csv")
df <- df[iv_sample == T & abs(Stringency) < 0.12 ] 

pdf("Figure_5_cc.pdf", fonts = "CM Sans")
par(mar = c(5,5,5,5))
with(df, hist(df$Stringency,axes = FALSE, breaks=60, ylab="", xlab="", bty="n", col="#1B9E77",border = "grey", main=NULL, prob = T))
axis(side = 2, col="white", col.ticks="black")
mtext("Density", side=2, line=2, family="CM Sans", cex=1.25)
axis(1, at = c(-0.09,-0.06, -0.03, 0.0, 0.03, 0.06, 0.09),col="white", col.ticks="black")

par(new = T)
with(df, plot(locfit(df$evicted~df$Stringency, kern="epa", deg=1), band="local", col="#D95F02", ylab="", xlab="", lwd=2, bty="n",axes="FALSE",family="CM Sans"))
axis(side = 4, col="white", col.ticks="black")
mtext("Pr(Eviction Order)", side=4, line=2.3, family="CM Sans", cex=1.25)
mtext("Stringency", side=1, line=2.75, family="CM Sans", cex=1.25)
dev.off()

embed_fonts("Figure_5_cc.pdf", outfile="Figure_5_cc.pdf")


